home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / grafix / tools / amipeg_0.4 / chunky2planar.s < prev    next >
Text File  |  1994-04-22  |  10KB  |  602 lines

  1. ;
  2. ; This source handles the conversion from 24-bit data to HAM8, initialization
  3. ; of the screen and so on.
  4. ;
  5. ; Support for Kaiko is not yet build-in, but very easy to accomplish, as it
  6. ; makes flush_cunkyloop completely obsolete. Looking forward to see
  7. ; custom logic like this, possibly more flexible, built-in in all Amigas.
  8. ;
  9. ; Phew! This one consumes 43% of the overall processor time in hires, 33% in
  10. ; lores. I want this Kaiko thingy!
  11. ;
  12. ;
  13. ; Michael Rausch  14-4-94  1:15:00
  14. ;
  15.  
  16.  
  17.     SECTION    text,CODE
  18.  
  19.     include    "graphics/rastport.i"
  20.     include    "graphics/gfx.i"
  21.  
  22.     XREF    _max_x
  23.     XREF    _max_y
  24.  
  25.  
  26.     XDEF    @HAM6_Init_lores
  27. @HAM6_Init_lores:
  28.     movem.l    d2-d7/a2-a6,-(sp)
  29.  
  30. ;         RGBG  BRGB  R=8 G=C B=4
  31. P7    set    %0111
  32. P8    set    %1101
  33.  
  34.     move.l    #(P7<<28)|(P7<<24)|(P7<<20)|(P7<<16)|(P7<<12)|(P7<<8)|(P7<<4)|P7,d5
  35.     move.l    #(P8<<28)|(P8<<24)|(P8<<20)|(P8<<16)|(P8<<12)|(P8<<8)|(P8<<4)|P8,d6
  36.  
  37.     move.l    a0,HAM8_rastport
  38.     move.l    (rp_BitMap,a0),a0
  39.  
  40.     moveq    #0,d1
  41.     move.w    (bm_BytesPerRow,a0),d1
  42.     move.l    d1,HAM8_offset        ; we have advanced one complete line when accessing this
  43.  
  44.     lea    (bm_Planes,a0),a6
  45.     move.l    a6,HAM8_screen
  46.  
  47.     move.l    (a6)+,a1
  48.     move.l    (a6)+,a2
  49.     move.l    (a6)+,a3
  50.     move.l    (a6)+,a4
  51.     move.l    (a6)+,a5
  52.     move.l    (a6),a6
  53.  
  54.     moveq.l    #0,d4
  55.  
  56.     lsr.l    #2,d1            ; longs
  57.     subq.l    #1,d1
  58.  
  59.     move.w    (bm_Rows,a0),d0
  60.     subq.w    #1,d0
  61. h6_prep_rows:
  62.  
  63.     move.l    d1,d2
  64. h6_prep_nulls:
  65.     move.l    d4,(a1)+
  66.     move.l    d4,(a2)+
  67.     move.l    d4,(a3)+
  68.     move.l    d4,(a4)+
  69.  
  70.     move.l    d5,(a5)+
  71.     move.l    d6,(a6)+
  72.  
  73.     dbra    d2,h6_prep_nulls
  74.  
  75.     dbra    d0,h6_prep_rows
  76.  
  77.     movem.l    (sp)+,d2-d7/a2-a6
  78.     rts
  79.  
  80.  
  81.  
  82.     XDEF    @HAM8_Init_lores
  83. @HAM8_Init_lores:
  84.     movem.l    d2-d7/a2,-(sp)
  85.  
  86. ;         RGBG  BRGB  R=8 G=C B=4
  87. P7    set    %0111
  88. P8    set    %1101
  89.  
  90.     move.l    #(P7<<28)|(P7<<24)|(P7<<20)|(P7<<16)|(P7<<12)|(P7<<8)|(P7<<4)|P7,d5
  91.     move.l    #(P8<<28)|(P8<<24)|(P8<<20)|(P8<<16)|(P8<<12)|(P8<<8)|(P8<<4)|P8,d6
  92.     bra.s    ham8cont
  93.  
  94.     XDEF    @HAM8_Init
  95. @HAM8_Init:                ; init from rastport data
  96.     movem.l    d2-d7/a2,-(sp)
  97.  
  98. ;         BRGB  R=8 G=C B=4
  99. P7    set    %1011
  100. P8    set    %0110
  101.  
  102.     move.l    #(P7<<28)|(P7<<24)|(P7<<20)|(P7<<16)|(P7<<12)|(P7<<8)|(P7<<4)|P7,d5
  103.     move.l    #(P8<<28)|(P8<<24)|(P8<<20)|(P8<<16)|(P8<<12)|(P8<<8)|(P8<<4)|P8,d6
  104.  
  105. ham8cont:
  106.     bsr    std_init
  107. prep_rows:
  108.  
  109.     move.l    d1,d2
  110. prep_nulls:
  111.     move.l    d4,(a1)+
  112.     move.l    d4,(a1)+
  113.     move.l    d4,(a1)+
  114.     move.l    d4,(a1)+
  115.     move.l    d4,(a1)+
  116.     move.l    d4,(a1)+
  117.     dbra    d2,prep_nulls
  118.  
  119.     move.l    a1,a0
  120.     add.l    a2,a0
  121.  
  122.     move.l    d1,d2
  123.     lsr.l    #1,d2            ; ohoh
  124. prep_cols67:
  125.     move.l    d5,(a1)+
  126.     move.l    d5,(a1)+
  127.     move.l    d6,(a0)+
  128.     move.l    d6,(a0)+
  129.     dbra    d2,prep_cols67
  130.  
  131.     add.l    a2,a1
  132.     dbra    d0,prep_rows
  133.  
  134.     movem.l    (sp)+,d2-d7/a2
  135.     rts
  136.  
  137.  
  138.  
  139.     XDEF    @HAM8_Init_x3
  140. @HAM8_Init_x3:                ; init from rastport data
  141.     movem.l    d2-d7/a2-a3,-(sp)
  142.  
  143.     bsr.s    std_init
  144. prep_rows_3:
  145.  
  146.     move.l    d1,d2
  147. prep_nulls_3:
  148.     move.l    d4,(a1)+
  149.     move.l    d4,(a1)+
  150.     move.l    d4,(a1)+
  151.     move.l    d4,(a1)+
  152.     move.l    d4,(a1)+
  153.     move.l    d4,(a1)+
  154.     dbra    d2,prep_nulls_3
  155.  
  156.     move.l    a1,a0
  157.     add.l    a2,a0
  158.  
  159.     lea    (scale3tab1,pc),a3
  160.     move.l    d1,d2
  161. prep_cols67_3:
  162.     move.l    (scale3tab2-scale3tab1,a3),(a0)+
  163.     move.l    (a3)+,(a1)+
  164.     subq.w    #1,d2
  165.     bmi.s    pc67_ready_3
  166.     move.l    (scale3tab2-scale3tab1,a3),(a0)+
  167.     move.l    (a3)+,(a1)+
  168.     subq.w    #1,d2
  169.     bmi.s    pc67_ready_3
  170.     move.l    (scale3tab2-scale3tab1,a3),(a0)+
  171.     move.l    (a3)+,(a1)+
  172.     sub.w    #3*4,a3
  173.     dbra    d2,prep_cols67_3
  174. pc67_ready_3:
  175.  
  176.     add.l    a2,a1
  177.     dbra    d0,prep_rows_3
  178.  
  179.     movem.l    (sp)+,d2-d7/a2-a3
  180.     rts
  181.  
  182. ;         BRG    R=8 G=C B=4
  183. P7    set    %101
  184. P8    set    %011
  185.  
  186. scale3tab1:
  187.     dc.l    (P7<<29)|(P7<<26)|(P7<<23)|(P7<<20)|(P7<<17)|(P7<<14)|(P7<<11)|(P7<<8)|(P7<<5)|(P7<<2)|(P7>>1)
  188.     dc.l    (P7<<31)|(P7<<28)|(P7<<25)|(P7<<22)|(P7<<19)|(P7<<16)|(P7<<13)|(P7<<10)|(P7<<7)|(P7<<4)|(P7<<1)|(P7>>2)
  189.     dc.l    (P7<<30)|(P7<<27)|(P7<<24)|(P7<<21)|(P7<<18)|(P7<<15)|(P7<<12)|(P7<<9)|(P7<<6)|(P7<<3)|P7
  190. scale3tab2:
  191.     dc.l    (P8<<29)|(P8<<26)|(P8<<23)|(P8<<20)|(P8<<17)|(P8<<14)|(P8<<11)|(P8<<8)|(P8<<5)|(P8<<2)|(P8>>1)
  192.     dc.l    (P8<<31)|(P8<<28)|(P8<<25)|(P8<<22)|(P8<<19)|(P8<<16)|(P8<<13)|(P8<<10)|(P8<<7)|(P8<<4)|(P8<<1)|(P8>>2)
  193.     dc.l    (P8<<30)|(P8<<27)|(P8<<24)|(P8<<21)|(P8<<18)|(P8<<15)|(P8<<12)|(P8<<9)|(P8<<6)|(P8<<3)|P8
  194.  
  195.  
  196.  
  197. std_init:
  198.     move.l    a0,HAM8_rastport
  199.     move.l    (rp_BitMap,a0),a0
  200.     moveq    #0,d1
  201.     move.w    (bm_BytesPerRow,a0),d1
  202.     move.l    (bm_Planes,a0),a1
  203.     move.l    a1,HAM8_screen
  204.     move.l    (bm_Planes+4,a0),a2
  205.     sub.l    a1,a2            ; plane delta
  206.  
  207.     cmp.l    a2,d1
  208.     bgt.s    check_interleaved
  209.     sub.l    a2,a2            ; RED ALERT, no interlaved bitmap or strange, weirdo layout!
  210. check_interleaved:
  211.     move.l    a2,HAM8_next
  212.     move.l    d1,HAM8_offset        ; we have advanced one complete line when accessing this
  213.  
  214.     moveq.l    #0,d4
  215.  
  216.     move.l    a2,d1
  217.     lsr.l    #2,d1            ; longs
  218.     subq.l    #1,d1
  219.  
  220.     move.w    (bm_Rows,a0),d0
  221.     subq.w    #1,d0
  222.     rts
  223.  
  224. ********************************************************
  225.  
  226.     XDEF    @HAM6_draw_lores    ;     (data=a0, x=d0, y=d1)
  227. @HAM6_draw_lores:
  228.     movem.l    d2-d7/a2-a4,-(sp)
  229.  
  230.     move.l    _max_y(a4),d7
  231.     cmp.l    d7,d1
  232.     bge.s    h6_max128lores
  233.     move.l    d1,d7        ; height
  234. h6_max128lores:
  235.     subq.l    #1,d7
  236.  
  237.     move.l    _max_x(a4),d1
  238.     cmp.l    d1,d0
  239.     bge.s    h6_max160lores
  240.     move.l    d0,d1        ; width
  241. h6_max160lores:
  242.  
  243.     move.l    d1,d6
  244.     lsr.w    #4,d6
  245.     subq.w    #1,d6        ; width in 8 pixel chunks
  246.  
  247.     and.w    #$fff0,d1    ; correct eol of over-large pix
  248.     sub.l    d1,d0
  249.  
  250.     move.l    d0,d2        ; this is some quick fix for 360 pixels wide b0.mpg, which is invalid!
  251.     and.w    #8,d2
  252.     add.w    d2,d0
  253.  
  254.     add.l    d0,d0        ; 1 word per pixel
  255.     move.l    d0,line_offset
  256.  
  257.     move.l    HAM8_screen,a1
  258.     addq.l    #4,a1
  259.     move.l    (a1)+,a2
  260.     move.l    (a1)+,a3
  261.     move.l    (a1),a4
  262.     move.l    -12(a1),a1
  263.  
  264.     move.l    HAM8_offset,d2
  265.     move.l    d6,d0
  266.     addq.l    #1,d0
  267.     lsl.l    #2,d0        ; writing one long per main loop
  268.     sub.l    d0,d2
  269.     move.l    d2,draw_offset
  270.  
  271. h6_draw_all_rows_lores:
  272.     move.l    d7,-(sp)
  273.     move.l    d6,d5
  274.  
  275. h6_blocks_loop_lores:
  276.  
  277.     moveq    #7,d4
  278. h6_flush_chunkyloop_lores:
  279.     move.w    (a0)+,d7        ; RGBG
  280.  
  281.     rept    4
  282.     add.w    d7,d7
  283.     addx.l    d0,d0
  284.     add.w    d7,d7
  285.     addx.l    d1,d1
  286.     add.w    d7,d7
  287.     addx.l    d2,d2
  288.     add.w    d7,d7
  289.     addx.l    d3,d3
  290.     endr
  291.  
  292.     dbra    d4,h6_flush_chunkyloop_lores
  293.  
  294.     move.l    d3,(a1)+
  295.     move.l    d2,(a2)+
  296.     move.l    d1,(a3)+
  297.     move.l    d0,(a4)+
  298.  
  299.     dbra    d5,h6_blocks_loop_lores
  300.  
  301.     add.l    line_offset,a0
  302.  
  303. ;    move.l    draw_offset,d1
  304. ;    add.l    d1,a1
  305. ;    add.l    d1,a2
  306. ;    add.l    d1,a3
  307. ;    add.l    d1,a4
  308.  
  309.     move.l    (sp)+,d7
  310.     dbra    d7,h6_draw_all_rows_lores
  311.  
  312.  
  313.     movem.l    (sp)+,d2-d7/a2-a4
  314.     rts
  315.  
  316.  
  317. ********************************************************
  318.  
  319.  
  320.     XDEF    @HAM8_draw_lores    ;     (data=a0, x=d0, y=d1)
  321. @HAM8_draw_lores:
  322.     movem.l    d2-d7/a2-a6,-(sp)
  323.  
  324.     move.l    _max_y(a4),d7
  325.     cmp.l    d7,d1
  326.     bge.s    max128lores
  327.     move.l    d1,d7        ; height
  328. max128lores:
  329.     subq.l    #1,d7
  330.  
  331.     move.l    _max_x(a4),d1
  332.     cmp.l    d1,d0
  333.     bge.s    max160lores
  334.     move.l    d0,d1        ; width
  335. max160lores:
  336.  
  337.     move.l    d1,d6
  338.     lsr.w    #4,d6
  339.     subq.w    #1,d6        ; width in 8 pixel chunks
  340.  
  341.     and.w    #$fff0,d1    ; correct eol of over-large pix
  342.     sub.l    d1,d0
  343.  
  344.     move.l    d0,d2        ; this is some quick fix for 360 pixels wide b0.mpg, which is invalid!
  345.     and.w    #8,d2
  346.     add.w    d2,d0
  347.  
  348.     add.l    d0,d0        ; 1 word per pixel
  349.     move.l    d0,line_offset
  350.  
  351.  
  352.     move.l    HAM8_screen,a1    ; get addr, prep next line
  353.     move.l    HAM8_next,d1
  354.     move.l    a1,a2
  355.     add.l    d1,a2
  356.     move.l    a2,a3
  357.     add.l    d1,a3
  358.     move.l    a3,a4
  359.     add.l    d1,a4
  360.     move.l    a4,a5
  361.     add.l    d1,a5
  362.     move.l    a5,a6
  363.     add.l    d1,a6
  364.  
  365.     move.l    HAM8_offset,d2
  366.     move.l    d6,d0
  367.     addq.l    #1,d0
  368.     lsl.l    #2,d0        ; writing one long per main loop
  369.     sub.l    d0,d2
  370.     move.l    d2,draw_offset
  371.  
  372.  
  373. draw_all_rows_lores:
  374.     move.l    d7,-(sp)
  375.     move.l    d6,-(sp)
  376.  
  377. blocks_loop_lores:
  378.     move.l    d6,-(sp)
  379.  
  380.     moveq    #7,d6
  381. flush_chunkyloop_lores:
  382.     move.l    (a0)+,d7        ; RGBG
  383.  
  384.     add.l    d7,d7
  385.     addx.l    d0,d0
  386.     add.l    d7,d7
  387.     addx.l    d1,d1
  388.     add.l    d7,d7
  389.     addx.l    d2,d2
  390.     add.l    d7,d7
  391.     addx.l    d3,d3
  392.     add.l    d7,d7
  393.     addx.l    d4,d4
  394.     add.l    d7,d7
  395.     addx.l    d5,d5
  396.  
  397.     rept    3
  398.     lsl.l    #3,d7
  399.     addx.l    d0,d0
  400.     add.l    d7,d7
  401.     addx.l    d1,d1
  402.     add.l    d7,d7
  403.     addx.l    d2,d2
  404.     add.l    d7,d7
  405.     addx.l    d3,d3
  406.     add.l    d7,d7
  407.     addx.l    d4,d4
  408.     add.l    d7,d7
  409.     addx.l    d5,d5
  410.     endr
  411.  
  412.     dbra    d6,flush_chunkyloop_lores
  413.     
  414.     move.l    d5,(a1)+
  415.     move.l    d4,(a2)+
  416.     move.l    d3,(a3)+
  417.     move.l    d2,(a4)+
  418.     move.l    d1,(a5)+
  419.     move.l    d0,(a6)+
  420.  
  421.     move.l    (sp)+,d6
  422.     dbra    d6,blocks_loop_lores
  423.  
  424.     add.l    line_offset,a0
  425.  
  426.     move.l    draw_offset,d1
  427.     add.l    d1,a1
  428.     add.l    d1,a2
  429.     add.l    d1,a3
  430.     add.l    d1,a4
  431.     add.l    d1,a5
  432.     add.l    d1,a6
  433.  
  434.     move.l    (sp)+,d6
  435.     move.l    (sp)+,d7
  436.     dbra    d7,draw_all_rows_lores
  437.  
  438.  
  439.     movem.l    (sp)+,d2-d7/a2-a6
  440.     rts
  441.  
  442.  
  443. ********************************************************
  444.  
  445.  
  446.     XDEF    @HAM8_draw_hires    ; (data=a0, x=d0, y=d1)
  447. @HAM8_draw_hires:
  448.     movem.l    d2-d7/a2-a6,-(sp)
  449.  
  450.     move.l    _max_y(a4),d7
  451.     cmp.l    d7,d1
  452.     bge.s    max128
  453.     move.l    d1,d7        ; height
  454. max128:    subq.l    #1,d7
  455.  
  456.     move.l    _max_x(a4),d1
  457.     cmp.l    d1,d0
  458.     bge.s    max160
  459.     move.l    d0,d1        ; width
  460. max160:
  461.  
  462.     move.l    d1,d6
  463.     lsr.w    #3,d6
  464.     subq.w    #1,d6        ; width in 8 pixel chunks
  465.  
  466.     and.w    #$fff8,d1    ; correct eol of over-large pix
  467.     sub.l    d1,d0
  468.     lsl.l    #2,d0        ; 1 long per pixel
  469.     move.l    d0,line_offset
  470.  
  471.  
  472.     move.l    HAM8_screen,a1        ; get addr, prep next line
  473.     move.l    HAM8_next,d1
  474.     move.l    a1,a2
  475.     add.l    d1,a2
  476.     move.l    a2,a3
  477.     add.l    d1,a3
  478.     move.l    a3,a4
  479.     add.l    d1,a4
  480.     move.l    a4,a5
  481.     add.l    d1,a5
  482.     move.l    a5,a6
  483.     add.l    d1,a6
  484.  
  485.     move.l    HAM8_offset,d2
  486.     move.l    d6,d0
  487.     addq.l    #1,d0
  488.     lsl.l    #2,d0
  489.     sub.l    d0,d2
  490.     move.l    d2,draw_offset
  491.  
  492. draw_all_rows:
  493.     move.l    d7,-(sp)
  494.     move.l    d6,-(sp)
  495.  
  496. blocks_loop:
  497.     move.l    d6,-(sp)
  498.  
  499.  
  500.     moveq    #7,d6
  501. flush_chunkyloop:
  502.     move.l    (a0)+,d7        ; BRG0
  503.  
  504.     add.l    d7,d7
  505.     addx.l    d0,d0
  506.     add.l    d7,d7
  507.     addx.l    d1,d1
  508.     add.l    d7,d7
  509.     addx.l    d2,d2
  510.     add.l    d7,d7
  511.     addx.l    d3,d3
  512.     add.l    d7,d7
  513.     addx.l    d4,d4
  514.     add.l    d7,d7
  515.     addx.l    d5,d5
  516.  
  517.     rept    2
  518.     lsl.l    #3,d7
  519.     addx.l    d0,d0
  520.     add.l    d7,d7
  521.     addx.l    d1,d1
  522.     add.l    d7,d7
  523.     addx.l    d2,d2
  524.     add.l    d7,d7
  525.     addx.l    d3,d3
  526.     add.l    d7,d7
  527.     addx.l    d4,d4
  528.     add.l    d7,d7
  529.     addx.l    d5,d5
  530.     endr
  531.  
  532.     add.l    d0,d0
  533.     add.l    d1,d1
  534.     add.l    d2,d2
  535.     add.l    d3,d3
  536.     add.l    d4,d4
  537.     add.l    d5,d5
  538.  
  539.     dbra    d6,flush_chunkyloop
  540.  
  541.  
  542.     move.l    #$11111111,d6
  543. copcol    macro    (reg)
  544.     move.l    \1,d7
  545.     lsr.l    #3,d7            ; BRGB
  546.     and.l    d6,d7
  547.     or.l    d7,\1
  548.     endm
  549.     copcol    d0
  550.     copcol    d1
  551.     copcol    d2
  552.     copcol    d3
  553.     copcol    d4
  554.     copcol    d5
  555.     
  556.     move.l    d5,(a1)+
  557.     move.l    d4,(a2)+
  558.     move.l    d3,(a3)+
  559.     move.l    d2,(a4)+
  560.     move.l    d1,(a5)+
  561.     move.l    d0,(a6)+
  562.  
  563.     move.l    (sp)+,d6
  564.     dbra    d6,blocks_loop
  565.  
  566.     add.l    line_offset,a0
  567.  
  568.     move.l    draw_offset,d1
  569.     add.l    d1,a1
  570.     add.l    d1,a2
  571.     add.l    d1,a3
  572.     add.l    d1,a4
  573.     add.l    d1,a5
  574.     add.l    d1,a6
  575.  
  576.     move.l    (sp)+,d6
  577.     move.l    (sp)+,d7
  578.     dbra    d7,draw_all_rows
  579.  
  580.  
  581.     movem.l    (sp)+,d2-d7/a2-a6
  582.     rts
  583.  
  584.  
  585. ********************************************************
  586.  
  587.  
  588.     SECTION    __MERGED,BSS
  589.  
  590.  
  591. HAM8_rastport:    ds.l    1            ; original rastport struct
  592. HAM8_screen:    ds.l    1            ; first bitplane
  593. HAM8_offset:    ds.l    1            ; next line in the first bitplane
  594. HAM8_next:    ds.l    1            ; next bitplane
  595.  
  596. draw_offset:    ds.l    1
  597. line_offset:    ds.l    1
  598.  
  599. is_interleaved: ds.w    1
  600.  
  601.     END
  602.